package com.biz.primus.ms.promotion.trans;

import com.biz.primus.model.promotion.vo.CutPriceSalePromotionVo;
import com.biz.primus.ms.promotion.dao.po.CutPriceSalePromotion;
import com.google.common.collect.Lists;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;

/**
 * 转换器(CutPriceSalePromotion --> CutPriceSalePromotionVo)
 *
 * @author david-liu
 */
public class CutPriceSalePromotionPo2VoMapper implements Function<CutPriceSalePromotion, CutPriceSalePromotionVo> {
    @Override
    public CutPriceSalePromotionVo apply(CutPriceSalePromotion cutPriceSalePromotion) {
        CutPriceSalePromotionVo vo = new CutPriceSalePromotionVo();
        vo.setId(cutPriceSalePromotion.getId());
        vo.setName(cutPriceSalePromotion.getName());
        vo.setDescription(cutPriceSalePromotion.getDescription());
        vo.setChannels(cutPriceSalePromotion.getChannels());
        vo.setStartTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(cutPriceSalePromotion.getStartTime()));
        vo.setEndTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(cutPriceSalePromotion.getEndTime()));
        vo.setEffectMemberLevels(cutPriceSalePromotion.getEffectMemberLevelStringList());
        vo.setScope(cutPriceSalePromotion.getScope());
        vo.setScopeIds(StringUtils.join(cutPriceSalePromotion.getScopeIds(), ","));
        vo.setUserOnceGainLimit(cutPriceSalePromotion.getUserOnceGainLimit());
        vo.setAllowCoupon(cutPriceSalePromotion.getAllowCoupon());
        vo.setCommonStatus(cutPriceSalePromotion.getCommonStatus());
        return vo;
    }

    public CutPriceSalePromotionVo map(CutPriceSalePromotion cutPriceSalePromotion) {
        return this.apply(cutPriceSalePromotion);
    }

    public List<CutPriceSalePromotionVo> mapWithList(List<CutPriceSalePromotion> cutPriceSalePromotionList) {
        return Optional.ofNullable(cutPriceSalePromotionList).orElse(Lists.newArrayList()).stream().map(this).collect(Collectors.toList());
    }
}
